<?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * @package     Pages Module
 * @author      Matrix Infoline (infolinematrix@gmail.com
 * @copyright   (c) Matrix Infoline
 */

class Index extends Frontend_Controller
{

	public function __construct()
	{
		parent::__construct();
		
		if($this->config->item('development') == true){
			$this->load->spark('codeigniter-forensics');
			$this->output->enable_profiler(true);
		}
		
	}


	public function _remap()
	{
		$ts=$this->uri->total_segments();
		$last_slug = end($this->uri->segments);
		$first_slag = $this->uri->segment(1, 0);

		
		$limit = 10;
		if($this->input->get('page') && $this->input->get('page') > 0){
			$offset = $this->input->get('page');
		}else{
			$offset = 0;
		}
		
		
		//--WIDGET--//
		$data['adsense'] = setting('adsense_pub_id');
		$data['widget_recent_listing'] = TRUE;
		$data['widget_popular_listing'] = TRUE;
		
		//print $ts; die(); 

		switch($ts){

			case 1:


				$locID = getSlugID('location',$last_slug); /* GET ID */
				
				

				if($locID){
					write_session('tmpLOC',$locID);
				}else{
					write_session('tmpLOC',0);
				}

				$data['module'] = 'LOCATION';
				$data['tmpLOC'] = get_session('tmpLOC');
				$data['tmpCAT'] = write_session('tmpCAT',0);

				Modules::run('browse/location/search',$data,0,2);
				break;
					
			case 2 :

				//--CATEGORY--//
				$catID = getSlugID('category',$last_slug); /* GET ID */

				

				if(isset($catID) && $catID !=0){
					write_session('tmpCAT',$catID);
				}else{
					write_session('tmpCAT',0);
				}

				$data['module'] = 'CATEGORY';
				$data['tmpLOC'] = get_session('tmpLOC');
				
				
				$data['tmpCAT'] = get_session('tmpCAT');
				
				
				
				Modules::run('browse/category/search',$data, $offset, $limit);
				break;

			
			case 3 :
				$postID = getID(current_url());
				//print $postID; die();
				$data['postID'] = getID(current_url());
				
				Modules::run('browse/profile/get',$data);
				break;
				
		}




	}

}
